﻿using GalaSoft.MvvmLight;

namespace httpExplorer.ViewModel
{
    public enum ProxySetting
    {
        ProxyDisable,
        ProxyUseSystemSettings,
        ProxyUseCustomSettings,
    }

    public enum ProxyAuthenticationSetting
    {
        ProxyAuthenticationLogin,
        ProxyAuthenticationBasic,
    }

    public class NetworkSettingsViewModel : ViewModelBase
    {
        ProxySetting _proxySetting = Properties.Settings.Default.ProxySetting;
        public ProxySetting ProxySetting
        {
            get { return _proxySetting; }
            set
            {
                if (_proxySetting == value)
                    return;

                _proxySetting = value;
                RaisePropertyChanged("ProxySetting");
                RaisePropertyChanged("IsProxyDisable");
                RaisePropertyChanged("IsProxySystem");
                RaisePropertyChanged("IsProxyCustom");
                Properties.Settings.Default.ProxySetting = value;
            }
        }

        public bool IsProxyDisable
        {
            get { return ProxySetting == ProxySetting.ProxyDisable; }
            set { ProxySetting = value ? ProxySetting.ProxyDisable : ProxySetting; }
        }

        public bool IsProxySystem
        {
            get { return ProxySetting == ProxySetting.ProxyUseSystemSettings; }
            set { ProxySetting = value ? ProxySetting.ProxyUseSystemSettings : ProxySetting; }
        }

        public bool IsProxyCustom
        {
            get { return ProxySetting == ProxySetting.ProxyUseCustomSettings; }
            set { ProxySetting = value ? ProxySetting.ProxyUseCustomSettings : ProxySetting; }
        }

        private string _proxyAddress = Properties.Settings.Default.ProxyAddress;
        public string ProxyAddress
        {
            get { return _proxyAddress; }
            set
            {
                if (_proxyAddress == value)
                    return;

                _proxyAddress = value;
                Properties.Settings.Default.ProxyAddress = value; 
                RaisePropertyChanged("ProxyAddress");
            }
        }

        private string _proxyPort = Properties.Settings.Default.ProxyPort;
        public string ProxyPort
        {
            get { return _proxyPort; }
            set
            {
                if (_proxyPort == value)
                    return;

                _proxyPort = value;
                Properties.Settings.Default.ProxyPort = value; 
                RaisePropertyChanged("ProxyPort");
            }
        }


        // Enable Proxy Authentication
        private bool _useProxyAuthentication = Properties.Settings.Default.IsUseProxyAuthentication;
        public bool UseProxyAuthentication
        {
            get { return _useProxyAuthentication; }
            set
            {
                if (_useProxyAuthentication == value)
                    return;

                _useProxyAuthentication = value;
                Properties.Settings.Default.IsUseProxyAuthentication = value; 
                RaisePropertyChanged("UseProxyAuthentication");
            }
        }

        // Proxy Authentication Settings
        ProxyAuthenticationSetting _proxyAuthenticationSetting = Properties.Settings.Default.ProxyAuthenticationSetting;
        public ProxyAuthenticationSetting ProxyAuthenticationSetting
        {
            get { return _proxyAuthenticationSetting; }
            set
            {
                if (_proxyAuthenticationSetting == value)
                    return;

                _proxyAuthenticationSetting = value;
                Properties.Settings.Default.ProxyAuthenticationSetting = value;
                RaisePropertyChanged("ProxyAuthenticationSetting");
                RaisePropertyChanged("IsProxyAuthenticationLogin");
                RaisePropertyChanged("IsProxyAuthenticationBasic");
            }
        }

        public bool IsProxyAuthenticationLogin
        {
            get { return ProxyAuthenticationSetting == ProxyAuthenticationSetting.ProxyAuthenticationLogin; }
            set { ProxyAuthenticationSetting = value ? ProxyAuthenticationSetting.ProxyAuthenticationLogin : ProxyAuthenticationSetting; }
        }

        public bool IsProxyAuthenticationBasic
        {
            get { return ProxyAuthenticationSetting == ProxyAuthenticationSetting.ProxyAuthenticationBasic; }
            set { ProxyAuthenticationSetting = value ? ProxyAuthenticationSetting.ProxyAuthenticationBasic : ProxyAuthenticationSetting; }
        }

        private string _proxyUsername = Properties.Settings.Default.ProxyUsername;
        public string ProxyUsername
        {
            get { return _proxyUsername; }
            set
            {
                if (_proxyUsername == value)
                    return;

                _proxyUsername = value;
                Properties.Settings.Default.ProxyUsername = value;
                RaisePropertyChanged("ProxyUsername");
            }
        }

        private string _proxyPassword = Properties.Settings.Default.ProxyPassword;
        public string ProxyPassword
        {
            get { return _proxyPassword; }
            set
            {
                if (_proxyPassword == value)
                    return;

                _proxyPassword = value;
                Properties.Settings.Default.ProxyPassword = value;
                RaisePropertyChanged("ProxyPassword");
            }
        }

        private string _proxyDomain = Properties.Settings.Default.ProxyDomain;
        public string ProxyDomain
        {
            get { return _proxyDomain; }
            set
            {
                if (_proxyDomain == value)
                    return;

                _proxyDomain = value;
                Properties.Settings.Default.ProxyDomain = value;
                RaisePropertyChanged("ProxyDomain");
            }
        }
    }
}
